<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">短信发送</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :model="form" label-width="80px" :inline="true" size="mini">
                    <el-form-item label="承租人:">
                        <div style="width: 150px">
                            <el-input v-model="form.czr" placeholder="请输入承租人" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="房屋地址:">
                        <div style="width: 150px">
                            <el-input v-model="form.fwdz" placeholder="请输入房屋地址" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="档案编号:">
                        <div style="width: 150px">
                            <el-input v-model="form.dabh" placeholder="请输入档案编号" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search" class="searchcolor">查询</el-button>
                        <el-button @click="reSearch" icon="el-icon-refresh" class="searchcolor">重置</el-button>
                        <!-- <el-button type="primary" @click="downloadlist" icon="el-icon-download"
                            class="searchcolor">导出</el-button> -->
                    </el-form-item>
                </el-form>
            </div>
            <el-button type="primary" @click="yzyclick" class="searchcolor" style="margin-bottom: 10px">发送</el-button>
            <el-table
                :data="tableData"
                style="width: 100%"
                :header-cell-style="tableHeaderColor"
                :row-style="tablerowColor"
                :row-class-name="tableRowClassName"
                :cell-style="tablecellColor"
                @selection-change="handleSelectionChange"
                border
                :max-height="maxHeight"
            >
                <el-table-column type="selection" width="40"> </el-table-column>
                <el-table-column prop="htbh" label="合同编号" align="center" fixed width="160"> </el-table-column>
                <el-table-column prop="dabh" label="档案编号" align="center" width="240" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="fwdz" label="房屋地址" align="center" width="280" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="czr" label="承租单位" align="center" width="240"> </el-table-column>
                <el-table-column prop="lxdh" label="联系电话" align="center">
                    <!-- <template slot-scope="scope">
                        <el-input
                            v-model="scope.row.czr"
                            placeholder="请输入承租单位"
                            class="search-input"
                            @change="changeMes(scope.row)"
                        ></el-input>
                    </template> -->
                </el-table-column>
                <el-table-column label="操作" width="100" align="center" fixed="right">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="editMsg(scope.row)">编辑</el-button>
                        <el-button type="text" size="small" @click="sendMsgone(scope.row.phone)">发送</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination
                    background
                    layout="total,sizes,prev, pager, next,jumper"
                    :total="total"
                    :current-page.sync="current"
                    :page-size="pageSize"
                    @current-change="handleCurrentChange"
                    :page-sizes="[10, 20, 30, 40, 50, 100]"
                    @size-change="handleSizeChange"
                >
                </el-pagination>
            </div>
        </div>
        <el-dialog title="联系电话" :visible.sync="editdialog" width="30%" center>
            <el-input v-model="newPhonenum.lxdh" placeholder="请输入联系电话" class="search-input"></el-input>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="editMsgsubmit">确 定</el-button>
            </span>
        </el-dialog>
        <el-dialog title="短信模板" :visible.sync="dialogVisible" width="80%" center>
            <div class="msgbox-card">
                <el-radio-group v-model="radio" style="width: 100%;">
                    <el-radio :label="3">
                        防汛
                        <el-card v-if="radio == 3" style="background-color: #eee;color: black !important;width: 98%;margin: 10px auto 0;font-weight: 500;" shadow="never">
                            <div>各房屋使用单位：</div>
                            <div style="margin: 10px 0;overflow-wrap: break-word;display: flex;flex-wrap: wrap;line-height: 32px;">
                                <p style="text-indent:2em">根据</p> 
                                <el-input v-model="msgform.tz" style="width: 200px;margin: 0 10px;"></el-input>
                                <p>通知，本市将迎来</p>
                                <el-input v-model="msgform.jy" style="width: 80px;margin: 0 10px;"></el-input>
                                <p>降雨，按照《天津市气象灾害应急预案》启动</p>
                                <el-input v-model="msgform.xy" style="width: 80px;margin: 0 10px;"></el-input>
                                <p>级应急响应，请各房屋使用单位提前采取</p>
                                <p>相应措施做好暴雨防范应对工作。</p>
                            </div>
                            <div>
                                <p style="text-indent:2em">特此通知</p>
                            </div>
                            <p style="text-align: right;margin-top: 10px;">天津市房产管理服务中心</p>
                            <div style="display: flex;justify-content: flex-end;width:100%;line-height: 32px;margin-top: 10px;">
                                <el-input v-model="msgform.year" style="width: 100px"></el-input>
                                <p>年</p>
                                <el-input v-model="msgform.month" style="width: 60px"></el-input>
                                <p>月</p>
                                <el-input v-model="msgform.day" style="width: 60px"></el-input>
                                <p>日</p>
                            </div>
                        </el-card>
                    </el-radio>
                    <el-radio :label="6">
                        紧急
                        <el-card v-if="radio == 6" style="background-color: #eee;color: black !important;width: 98%;margin: 10px auto 0;font-weight: 500;" shadow="never">
                            <div>各房屋使用单位：</div>
                            <div style="margin: 10px 0;overflow-wrap: break-word;display: flex;flex-wrap: wrap;line-height: 32px;">
                                <p style="text-indent:2em">深刻汲取</p>
                                <el-input v-model="msgform.jx" style="width: 80%;margin: 0 10px;"></el-input>
                            </div>
                            <div style="white-space: normal;width: 100%;line-height: 32px;margin-bottom: 20px;">
                                事故教训，持续加强房管中心自有房产安全管理工作，根据房管中心统一部署要求，请各房屋使用单位全面排查各种安全隐患，一全面排查房产燃气使用安全；二全面排查房产消防安全；三是全面排查电器、线路安全。请各房屋使用单位要高度警醒，举一反三，增强忧患意识，树牢底线思维坚决防范遏制各类安全事故发生，切实做好房屋安全管理工作。
                            </div>
                            <div>
                                <p style="text-indent:2em">特此通知</p>
                            </div>
                            <p style="text-align: right;margin-top: 10px;">天津市房产管理服务中心</p>
                            <div style="display: flex;justify-content: flex-end;width:100%;line-height: 32px;margin-top: 10px;">
                                <el-input v-model="msgform.year" style="width: 100px"></el-input>
                                <p>年</p>
                                <el-input v-model="msgform.month" style="width: 60px"></el-input>
                                <p>月</p>
                                <el-input v-model="msgform.day" style="width: 60px"></el-input>
                                <p>日</p>
                            </div>
                        </el-card>
                    </el-radio>
                    <el-radio :label="9">
                        节日
                        <el-card v-if="radio == 9" style="background-color: #eee;color: black !important;width: 98%;margin: 10px auto 0;font-weight: 500;" shadow="never">
                            <div>各房屋使用单位：</div>
                            <div style="margin: 10px 0;overflow-wrap: break-word;display: flex;flex-wrap: wrap;line-height: 32px;">
                                <el-input v-model="msgform.jr" style="width:80px;margin: 0 10px 0 20px;"></el-input>
                                <p>节将至，为切实加强安全生产工作，请各房屋使用单位严格落实安全主体责任，全面排查安全隐患，严守不发生事故底线，现就有关事项</p>
                                <p>要求如下：</p>
                            </div>
                            <div style="white-space: normal;width: 100%;line-height: 32px;margin-bottom: 10px;text-indent:2em">
                                一、确保各类防火安全设施能正常使用，安全警示标志设置符合规范；通道畅通，在紧急情况下能够快速疏散
                            </div>
                            <div style="white-space: normal;width: 100%;line-height: 32px;margin-bottom: 10px;text-indent:2em">
                                二、确保经营房产燃气管线无泄露、燃气泄漏报警装置能正常使用，严格执行燃气安全使用的有关法律、法规和安全技术规范的相关规定
                            </div>
                            <div style="white-space: normal;width: 100%;line-height: 32px;margin-bottom: 10px;text-indent:2em">
                                三、确保电线无私自拆、改、电器设备无老化、损坏，室内不得停放电动车及电池，不得室内充电。严格执行电器设备安全使用的有关法律、法规和安全技术规范的相关规定
                            </div>
                            <div style="white-space: normal;width: 100%;line-height: 32px;margin-bottom: 10px;text-indent:2em">
                                四、如在节假日发生安全事故的，请及时与我中心取得联系
                            </div>
                            <div style="white-space: normal;width: 100%;line-height: 32px;margin-bottom: 20px;text-indent:2em">
                                同时各房屋使用单位要高度警醒，举一反三，增强忧患意识，树牢底线思维，对房屋排查出的隐患及时整改，着力将各类问题和安全隐患消除在萌芽阶段降低风险。
                            </div>
                            <div>
                                <p style="text-indent:2em">特此通知</p>
                            </div>
                            <p style="text-align: right;margin-top: 10px;">天津市房产管理服务中心</p>
                            <div style="display: flex;justify-content: flex-end;width:100%;line-height: 32px;margin-top: 10px;">
                                <el-input v-model="msgform.year" style="width: 100px"></el-input>
                                <p>年</p>
                                <el-input v-model="msgform.month" style="width: 60px"></el-input>
                                <p>月</p>
                                <el-input v-model="msgform.day" style="width: 60px"></el-input>
                                <p>日</p>
                            </div>
                        </el-card>
                    </el-radio>
                </el-radio-group>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="sendMsg">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { zjinfolist, projectdelete, yzyinfo, exportzjinfolist, zjinfoupdate, getsignlist, getsignlistupdate } from '@/api/index';
export default {
    name: 'dalist',
    data() {
        return {
            newPhonenum: {
                id: '',
                lxdh: ''
            }, //新的电话
            editdialog: false,
            dialogVisible: true,
            radio: 3,
            total: 0,
            current: 1,
            pageSize: 10,
            form: {
                create_name: '', // 创建人
                create_name_id: '', // 创建人id ,
                create_time: '', // 创建时间 ,
                current: 1, // 第几页 ,
                czmj: '', // 出租面积 ,
                czr: '', //承租人 ,
                czrlxfs: '', //承租人联系方式 ,
                dabh: '', //档案编号 ,
                db: '', //电表 ,
                fj: '', //附件 ,
                fwdz: '', //房屋地址 ,
                glfs: '', //管理方式 出租经营 委托管理 ,
                htbh: '', //合同编号 ,
                htdqsj: '', //合同到期时间（签订时约定时间） ,
                htje: '', //合同金额 ,
                htzzsj: '', //合同中止时间 ,
                htzzyy: '', //合同中止原因 ,
                id: '', //id ,
                jmje: '', //减免金额 ,
                jmyy: '', //减免原因 ,
                lxdz: '', //联系地址 ,
                lxdh: '', //联系电话
                ndgrf: '', // 年度供热费 ,
                pageSize: 10, //每页数量 ,
                qdsj: '', //合同签订时间 ,
                relid: '', //关联ID ,
                rqb: '', //燃气表 ,
                rzfj: '', //入住附件 ,
                sbqd: '', //设备清单 ,
                shb: '', //水表 ,
                status_code: 1, //1正常 2删除 ,
                stdwid: '', //受托单位ID ,
                type: '', //分类 1:房间 2：楼栋 ,
                update_name: '', //修改人 ,
                update_name_id: '', //修改人id ,
                update_time: '', //修改时间 ,
                wyf: '', //物业费 ,
                yj: '', //押金 ,
                ysje: '', //预收金额 ,
                zjdj: '', //租金单价 ,
                zjhm: '', //证件号码 ,
                zjmc: '', //证件名称 ,
                zldqsj: '', //租赁到期时间（提前中止修改） ,
                zlqssj: '', //租赁起始时间 ,
                zlqx: '', //租赁期限 ,
                zlyt: '' //租赁用途
            },
            tableData: [],
            multipleSelection: [], //预转已选中列表
            yzylist: [
                { name: '是', code: '1' },
                { name: '否', code: '0' }
            ],
            maxHeight: null,
            msgform:{
                tz:'',
                yx:"",
                year:'',
                month:'',
                day:''
            }
        };
    },
    components: {},
    computed: {
        // 判断变色
        getcolorred(htzt) {
            console.log(htzt);
            return (htzt) => {
                if (htzt == '正常') {
                    return { color: '#19BE6B', fontWeight: 700 };
                } else if (htzt == '已经到期') {
                    return { color: '#D9001B', fontWeight: 700 };
                } else if (htzt == '即将到期') {
                    return { color: '#FF9900', fontWeight: 700 };
                } else if (htzt == '未签合同') {
                    return { color: '#409ee1', fontWeight: 700 };
                }
            };
        }
    },
    methods: {
        // var data = datas.find((item) => item.id == "1"); 使用find方法找到数组中对应的对象
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;';
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black';
        },
        tablecellColor() {
            return 'font-weight:700;color:#000000;border-color:#c0c0c0';
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row'; //这是类名
            } else {
                return '';
            }
        },
        //修改数据
        changeMes(e) {
            console.log('已修改数据', e);
            this.zjinfoupdate(e);
        },
        // 编辑数据
        editMsg(e) {
            let msgform = JSON.parse(JSON.stringify(e));
            this.newPhonenum.lxdh = msgform.lxdh;
            this.newPhonenum.id = msgform.id;
            this.editdialog = true;
        },
        editMsgsubmit() {
            console.log(this.newPhonenum);
            this.getsignlistupdate(this.newPhonenum);
        },
        //编辑数据接口
        getsignlistupdate(data) {
            getsignlistupdate(data).then((res) => {
                if (res.code == 200) {
                    this.$message.success('修改成功！！！');
                    this.editdialog = false;
                    this.getsignlist(this.form);
                } else {
                    this.$message.error('修改失败！！！');
                }
            });
        },
        // 确定发送信息
        sendMsg() {
            let newwMsg = [];
            this.multipleSelection.map((item) => {
                newwMsg.push({ czr: item.czr, msgnum: this.radio });
            });
            console.log('上传的内容', newwMsg);
        },
        // 确定发送信息(单独一条的)
        sendMsgone(e) {
            this.dialogVisible = true;
            console.log(e);
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.form.pageSize = this.pageSize;
            this.getsignlist(this.form);
            console.log(val);
        },
        // 每页条数
        handleSizeChange(val) {
            this.current = 1;
            this.pageSize = val;
            this.form.pageSize = val;
            this.getsignlist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.getsignlist(this.form);
            console.log('搜索');
        },
        // 重置
        reSearch() {
            this.current = 1;
            this.pageSize = 10;
            this.form = {
                create_name: '',
                create_name_id: '',
                create_time: '',
                current: 1,
                czdz: '',
                czmj: '',
                czr: '',
                czrlxfs: '',
                dabh: '',
                db: '',
                fj: '',
                fwdz: '',
                glfs: '',
                htbh: '',
                htdqsj: '',
                htje: 0,
                htzzsj: '',
                htzzyy: '',
                id: '',
                jmje: 0,
                jmyy: '',
                lxdz: '',
                lxdh: '',
                ndgrf: '',
                pageSize: 10,
                qdsj: '',
                relid: '',
                rqb: '',
                rzfj: '',
                sbqd: '',
                sbqk: '',
                shb: '',
                status_code: 0,
                stdwid: '',
                type: '',
                update_name: '',
                update_name_id: '',
                update_time: '',
                wyf: '',
                yj: 0,
                ysje: 0,
                zjdj: 0,
                zjhm: '',
                zjmc: '',
                zldqsj: '',
                zlqssj: '',
                zlqx: '',
                zlyt: ''
            };
            this.getsignlist(this.form);
            console.log('搜索');
        },
        // 添加
        addnew() {
            this.$router.push({
                name: 'addproject',
                path: '/addproject'
            });
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = { id: e.id };
                    projectdelete(data).then((res) => {
                        if (res.code == 200) {
                            this.getsignlist(this.form);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 项目列表
        getsignlist(data) {
            getsignlist(data).then((res) => {
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        },
        // 编辑租金信息
        zjinfoupdate(data) {
            zjinfoupdate(data).then((res) => {
                if (res.code == 200) {
                    this.$message.success('修改成功！！！');
                } else {
                    this.$message.error('修改失败！！！');
                }
            });
        },
        // 预转已接口
        yzyinfo(data) {
            yzyinfo(data).then((res) => {
                if (res.code == 200) {
                    this.$message.success('提交成功');
                    this.zjinfolist(this.form);
                }
            });
        },
        // 预转已点击事件
        yzyclick() {
            if (this.multipleSelection.length == 0) {
                this.$message.error('请选择发送对象');
            } else {
                this.dialogVisible = true;
            }
            // let newlist = [];
            // let data = {
            //     current: 0,
            //     pageSize: 0,
            //     signlist: []
            // };
            // this.multipleSelection.map((item) => {
            //     newlist.push({ id: item.signid });
            // });
            // data.signlist = newlist;
            // this.yzyinfo(data);
            // console.log('data', data);
        },
        // 多条预转已点击事件
        handleSelectionChange(val) {
            console.log('val', val);
            this.multipleSelection = val;
        },
        // 是否预转已
        onchangeradio(val) {
            this.zjinfolist(this.form);
            console.log(this.form.yzy);
        },
        // 导出
        downloadlist() {
            exportzjinfolist(this.form).then((res) => {
                console.log(res);
                const link = document.createElement('a');
                let blob = new Blob([res], {
                    type: 'application/vnd.ms-excel'
                });
                link.style.display = 'none';
                //设置连接
                link.href = URL.createObjectURL(blob);
                link.download = '交款导出文件';
                document.body.appendChild(link);
                //模拟点击事件
                link.click();
                console.log(res);
            });
        }
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 440;
        });
        this.getsignlist(this.form);
    }
};
</script>

<style scoped>
/* 单选样式强制修改成纵向的*/
::v-deep .msgbox-card .el-radio {
    width: 90%;
    display: block;
    margin: 10px 0;
}
.container {
    /* height: calc(100vh - 260px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}
</style>
<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>
